package com.yaowk.system.server.controller;

import com.yaowk.common.api.PageReq;
import com.yaowk.common.api.PageResp;
import com.yaowk.security.utils.ISecurityUtils;
import com.yaowk.system.api.LoginApi;
import com.yaowk.system.api.model.Login;
import com.yaowk.system.server.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "登录日志")
public class LoginController implements LoginApi {

    @Autowired
    private ILoginService loginService;
    @Autowired
    private ISecurityUtils securityUtils;

    @Override
    @ApiOperation("日志列表")
    public PageResp<Login> list(Login login, PageReq pageReq) {
        return loginService.findAll(login, pageReq);
    }

    @Override
    @ApiOperation("我的登录日志")
    public PageResp<Login> selfList(Login login, PageReq pageReq) {
        login.setUserId(securityUtils.getUserId());
        return loginService.findAll(login, pageReq);
    }

    @Override
    @ApiOperation("保存登录日志")
    public Login save(Login login) {
        return loginService.save(login);
    }

    @Override
    @ApiOperation("删除登录日志")
    public void delete(@PathVariable Long id) {
        loginService.deleteById(id);
    }
}
